# 统计代码行数
import os
def countLine(tail):
    files = os.listdir()  # 读入文件夹
    file_count = 0
    lines = 0
    cpp_h = []
    for item in files:
        for x in tail:
            if item.endswith(x):
                file_count += 1
                cpp_h.append(item)
                break
    for file in cpp_h:
        with open(file, "r", encoding="utf-8") as f:
            temp = f.readlines()
            lines += len(temp)
            # print(temp)
    print(lines)

tail1 = ["cpp", "h"]
print(".cpp & .h")

tail2 = ["cpp", "h", "ui"]
print(".cpp & .h & .ui")


# 生成cpp h 文件源代码
all = ""
files = os.listdir()  # 读入文件夹
cpp_h = []
for item in files:
    for x in tail1:
        if item.endswith(x):
            cpp_h.append(item)
            break
c = 0
for file in cpp_h:
    all += file
    all += '\n'
    all += '\n'
    with open(file, "r", encoding="utf-8") as f:
        temp = f.readlines()
        for line in temp:
            all += line
            c += 1
        all += '\n'

print(all)
with open("code.txt", "w") as f:
    f.write(all)
print(c)
countLine(tail1)
countLine(tail2)